import Mock from 'mockjs'
import carAPI from './car'

// 修复在使用 MockJS 情况下，设置 withCredentials = true，且未被拦截的跨域请求丢失 Cookies 的问题
// https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Mock.XHR.prototype.send = function () {
  if (this.custom.xhr) {
    this.custom.xhr.withCredentials = this.withCredentials || false
  }
  this.proxy_send(...arguments)
}

Mock.mock(/\/mock\/car\/gethotautobrand/, 'get', carAPI.gethotautobrand)
Mock.mock(/\/mock\/car\/getallautobrand/, 'get', carAPI.getallautobrand)
Mock.mock(/\/mock\/car\/getautoselectbybrand/, 'get', carAPI.getautoselectbybrand)
Mock.mock(/\/mock\/car\/getautoinfobyvin/, 'get', carAPI.getautoinfobyvin)
Mock.mock(/\/mock\/car\/searchpartitems/, 'get', carAPI.searchpartitems)

export default Mock
